﻿// ———————————————————————–
// <copyright file="ValueListService.svc.cs" company="The MITRE Corporation">
//    Copyright (c) 2010 The MITRE Corporation. All rights reserved.
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//    http://www.apache.org/licenses/LICENSE-2.0
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
// ———————————————————————–
/////////////////////////////////////////////////////////////////////////////////////////////////
// ValueListService.svc.cs - "Interfaces With The DAL To Update, Obtain, Or Delete ValueLists."
// Project: "IC.NETSOA"- "ICNETREST"
//
// Language:    C#, .NET 4.0
// Platform:    Windows 7, VS 2010
// Author:      Don McGarry The MITRE Corporation
/////////////////////////////////////////////////////////////////////////////////////////////////

// Copyright (c) 2010 The MITRE Corporation. All rights reserved.
//
// NOTICE
// This software was produced for the U. S. Government
// under Contract No. FA8721-09-C-0001, and is
// subject to the Rights in Noncommercial Computer Software
// and Noncommercial Computer Software Documentation Clause
// (DFARS) 252.227-7014 (JUN 1995)
                
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Xml.Linq;
using ICNETDAL;
using ICNETSerializers;

namespace ICNETREST
{
  /// <summary>
  /// Communicates with the DAL to modify ValueLists or their contents. 
  /// </summary>
  [ServiceContract(Namespace = "urn:icnet:mitre:org:ValueListService")]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  public class ValueListService
  {
    /// <summary>
    /// Gets the content keywords stored in the database.
    /// </summary>
    /// <returns>An XML object containing the content keywords.</returns>
    [WebGet(UriTemplate = "/", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare), OperationContract]
    public XElement GetValueLists()
    {
      return AWSValueListDAL.GetValueListXML("");
    }


    /// <summary>
    /// Get all of the roles in a certain ValueList.
    /// </summary>
    /// <param name="listName">The value list to search for.</param>
    /// <returns>An XML object containing all of the roles for a certain value list.</returns>
    [WebGet(UriTemplate = UriTemplates.ValListUri, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare), OperationContract]
    public XElement GetValueList(string ValueListURN)
    {
     return AWSValueListDAL.GetValueListXML(ValueListURN);
    }

    /// <summary>
    /// Adds a new ValueList to the database.
    /// </summary>
    /// <param name="xe">The ValueList to be added.</param>
    /// <returns>An XML object containing the ValueListand its ID, or an error if it was not sucesfully created.</returns>
    [WebInvoke(UriTemplate = "/ValueList", Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
    public XElement CreateNewValueList(XElement xe)
    {
      return AWSValueListDAL.AddValueList(ValListsHelper.FromXElement(xe)); 
    }


    /// <summary>
    /// Deletes a ValueList from the database.
    /// </summary>
    /// <param name="Id">The ID of the ValueList to be deleted.</param>
    /// <returns>An XML object containing the ID of the ValueList and its ID in one element.</returns>
    [WebInvoke(UriTemplate = UriTemplates.FullValListUri, Method = "DELETE", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare), OperationContract]
    public XElement DeleteValueList(string ValueListURN, string Value)
    {
      return AWSValueListDAL.DeleteValueList(ValueListURN, Value);
    }
  }
}

